package v1

import (
    "authserver/global"
    "authserver/global/response"
    "authserver/model"
    "authserver/service"
    "github.com/gin-gonic/gin"
)

// InvoiceCheck @Tags xy_record
// @Summary
// @Router /invoice/check [post]
func InvoiceCheck(c *gin.Context) {

    var req model.InvoiceReq

    _=c.ShouldBindJSON(&req)

    if req.Username == "" {
        global.GVA_LOG.Error("请输入注册码....")
        response.FailWithMessage("请输入注册码", c)
        return
    }
    if req.ImgUrl==""{
        global.GVA_LOG.Error("请输入解析图片....")
        response.FailWithMessage("请输入解析图片", c)
        return
    }
    resp,err := service.InvoiceCheck(req.ImgUrl,req.Username)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
    } else {
        response.OkWithData(resp,c)
    }
}
// SaveInvoice
// @Summary
// @Router /invoice/save [post]
func SaveInvoice(c *gin.Context) {

    var req model.InvoiceCheckInfo

    _=c.ShouldBindJSON(&req)

    if req.CheckUser == "" {
        global.GVA_LOG.Error("提交信息有误....")
        response.FailWithMessage("提交信息有误", c)
        return
    }
    if req.InvoiceCode==""{
        global.GVA_LOG.Error("提交信息有误")
        response.FailWithMessage("提交信息有误", c)
        return
    }
    err := service.SaveCheckInfo(req)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
    } else {
        response.OkWithMessage("提交成功",c)
    }
}
